package com.devplatform.schedule;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.devplatform.pojo.EmailCode;
import com.devplatform.service.EmailCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;

@Component
public class clearSchedule {
    @Autowired
    private EmailCodeService emailCodeService;

    //每周一4点删除前一周所发送的验证码
    @Scheduled(cron = "0 0 4 * * MON")
    public void clearEmailCode() {
        LambdaQueryWrapper<EmailCode> wrapper = new LambdaQueryWrapper<>();
        wrapper.lt(EmailCode::getSendTime, LocalDate.now().minusDays(7));
        emailCodeService.remove(wrapper);
    }

}
